#coding=utf-8
import urllib2

def _visit(site, opener):
    if site.find("://") == -1:
        site = "http://" + site    
    urllib2.socket.setdefaulttimeout(90)
    
    request = urllib2.Request(site)
    request.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.8.1.14) Gecko/20080404 (FoxPlus) Firefox/2.0.0.14')
    request.add_header('Accept', "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, */*")
    request.add_header("Accept-Language","zh-cn") # 加入头信息，这样可以避免403错误
    request.add_header("Content-Type","text/html; charset=utf8") 
    
    page = opener.open(request)
    data = page.read()
    page.close()
    return data

def visit(site):
    _opener = urllib2.build_opener(urllib2.HTTPHandler, 
                                   urllib2.HTTPCookieProcessor())
    return _visit(site, _opener)
